<!DOCTYPE html>
<html lang="zn">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>项目列表</title>
  <meta name="description" content="">
  <meta name="author" content="templatemo">
  <link href="../css/font-awesome.min.css" rel="stylesheet">
  <link href="../css/bootstrap.min.css" rel="stylesheet">
  <link href="../css/templatemo-style.css" rel="stylesheet">
  <link href="../css/admin.css" rel="stylesheet">
  <script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
  <script src="../js/admin.js"></script>
</head>
<!-- <script>
  function download() {
    $.ajax({
      type: "POST",
      url: 'download.php',
      async: false,
      dataType: "json",
      data: $('#download').serialize(),
      success: function(msg) {
        if (msg.status == 1) {
          alert(msg.mes);
          window.location.reload();
        }
        if (msg.status == -1) {
          alert(msg.mes);
          window.location.reload();
        }
      },
      // error: function (XMLHttpRequest, textStatus, errorThrown) {
      //     alert(XMLHttpRequest.readyState);
      //     alert(textStatus);
      // }
    });
  }
</script> -->
<script>
  function delpro(id) {
    if (window.confirm('确定删除吗？')) {
      $.ajax({
        type: "GET",
        url: 'dodelPro.php',
        async: false,
        dataType: "json",
        data: {
          'pid': id
        },
        success: function(msg) {
          if (msg.status == 1) {
            alert(msg.mes);
            window.location.reload();
          }
          if (msg.status == -1) {
            alert(msg.mes);
            window.location.reload();
          }
        },
        error: function(result) {
          alert('请求失败!');
        }
      });
    }
  }
</script>
<script>
  $(function() {
    var x = 1;
    $('#sAll').on('click', function() {
      if (x == 1) { //全选
        $("tbody input[name='p1[]']").prop("checked", true);
        $('#sAll').val('取消');
        x = 0;
      } else { //取消全选
        $("tbody input[name='p1[]']").prop("checked", false);
        $('#sAll').val('全选');
        x = 1;
      }
    });
    //反选
    $("#fSel").click(function() {
      $("tbody input[name='p1[]']").each(function() {
        $(this).prop('checked', !$(this).prop('checked'));
      });
    })
  });
</script>

<body>
  <?php
  require_once "../congfig/config.php";
  require_once "../lib/common.php";
  session_start();
  checkAdmin();
  $sql = "select * from proinfor";
  $query = $GLOBALS['conn']->query($sql);
  $num = $query->num_rows;
  $pagesize = 7;
  $page = empty($_GET['page']) ? 1 : $_GET['page'];
  $prepage = $page - 1;
  $nextpage = $page + 1;
  $tatolpage = ceil($num / $pagesize);
  $startpage = ($page - 1) * $pagesize;
  @$key = $_GET['key'];
  if (isset($key)) {
    $sql = "select * from proinfor where pName like '%$key%'";
    $query = $GLOBALS['conn']->query($sql);
  } else {
    $sql = "select * from proinfor  LIMIT $startpage,$pagesize ";
    $query = $GLOBALS['conn']->query($sql);
    // $result=$query1->fetch_array();
    // echo $result['pName'];
  }

  ?>

  <!-- Left column -->
  <div class="templatemo-flex-row">
    <div class="templatemo-sidebar">
      <header class="templatemo-site-header">
        <div class="square"></div>
        <h1>后台管理系统</h1>

      </header>

      <div class="profile-photo-container">
        <img src="../images/profile-photo.jpg" alt="Profile Photo" class="img-responsive">
      </div>
      <!-- Search box -->

      <div class="mobile-menu-icon">
        <i class="fa fa-bars"></i>
      </div>
      <nav class="templatemo-left-nav">
        <ul>
          <li id="xmgl"><a href="#" class="active"><i class="fa fa-bars fa-fw"></i>项目管理</a>
            <ul>
              <li><a href="addProject.php"><i class="fa fa-bars fa-fw"></i>添加项目</a></li>
            </ul>
            <ul>
              <li><a href="applyproject.php"><i class="fa fa-bars fa-fw"></i>申请立项</a></li>
            </ul>
            <ul>
              <li><a href="projectsucc.php"><i class="fa fa-bars fa-fw"></i>立项成功</a></li>
            </ul>
            <ul>
              <li><a href="projectfail.php"><i class="fa fa-bars fa-fw"></i>立项失败</a></li>
            </ul>
            <ul>
              <li><a href="applyprojectover.php"><i class="fa fa-bars fa-fw"></i>申请结项</a></li>
            </ul>
            <ul>
              <li><a href="projectok.php"><i class="fa fa-bars fa-fw"></i>结项成功</a></li>
            </ul>
            <ul>
              <li><a href="projectnok.php"><i class="fa fa-bars fa-fw"></i>结项失败</a></li>
            </ul>
            <ul>
              <li><a href="goodpro.php"><i class="fa fa-bars fa-fw"></i>优秀项目</a></li>
            </ul>
          </li>
          <li id="yhgl"><a href="user-list.php"><i class="fa fa-user fa-fw"></i>用户管理</a>
            <ul>
              <li><a href="addUser.php"><i class="fa fa-user fa-fw"></i>添加用户</a></li>
            </ul>
          </li>
          <li><a href="pad-check.php"><i class="fa fa-cog fa-fw"></i>修改密码</a></li>
          <li><a href="../loginout.php" id="zx"><i class="fa fa-map-marker fa-fw"></i>注销</a></li>
        </ul>
      </nav>
    </div>
    <!-- Main content -->
    <div class="templatemo-content col-1 light-gray-bg" style="height:1000px;">
      <div class="container" style="margin-top:100px;">
        <form action="download.php" method="post">
          <div role="tabpanel" class="tab-pane active" id="sour">
            <div class="check-div form-inline">
              <!-- <form action="#" method="GET">
            <div class="col-xs-4">
              <input type="text" class="form-control input-sm"  name="key" placeholder="输入项目名搜索">
              <button type="submit" class="btn btn-white btn-xs  ">查 询 </button>
            </div>
            </form> -->
              <div class="data-div">
                <!-- <button id="sAll" value="全选" class="btn btn-info btn-sm"> 全选</button> -->
                <input type="button" name="" id="sAll" value="全选" class="btn btn-info btn-sm">
                <input type="button" name="" id="fSel" value="反选" class="btn btn-success btn-sm">
                <!-- <a class="btn btn-success btn-xs" href="">通过</a>
                    <a class="btn btn-danger btn-xs" href="">不通过</a> -->
              </div>
            </div>
            <div class="data-div">
              <!-- <form id = "download"> -->
              <table class="table table-hover table-striped">
                <thead>
                  <tr>
                    <td></td>
                    <td>编号</td>
                    <td>项目名称</td>
                    <td>项目负责人</td>
                    <td>指导教师</td>
                    <td>操作</td>
                    <td>项目状态</td>
                  </tr>
                </thead>
                <tbody>
                  <?php
                  $i = 1;
                  while ($result = $query->fetch_array()) {
                    ?>
                    <tr>
                      <th><input type="checkbox" name="p1[]" value="<?php echo $result["id"]; ?>"></th>
                      <th><?php echo $i++; ?></th>
                      <th><?php echo $result["pName"]; ?> </th>
                      <?php
                      $username = $result["pChar"];
                      $sql1 = "select * from userinfor where uid =(select uid from users where username='$username')";
                      $query1 = $conn->query($sql1);
                      $result1 = $query1->fetch_array();
                      ?>
                      <th><?php echo $result1["realname"]; ?></th>
                      <?php
                      $username1 = $result["teacher"];
                      $sql2 = "select * from userinfor where uid =(select uid from users where username='$username1')";
                      $query2 = $conn->query($sql2);
                      $result2 = $query2->fetch_array();
                      ?>
                      <th><?php echo $result2["realname"]; ?></th>
                      <th>
                        <a class="btn btn-info btn-xs" href="projectinfor.php?pid=<?php echo $result['id'] ?>">查看</a>
                        <a class="btn btn-info btn-xs" href="alterProjectUser.php?pid=<?php echo $result['id'] ?>">成员管理</a>
                        <a class="btn btn-warning btn-xs" href="addProjectUser.php?pid=<?php echo $result['id'] ?>">添加成员</a>
                        <a class="btn btn-success btn-xs" href="alterProject.php?pid=<?php echo $result['id'] ?>">修改</a>
                        <button class="btn btn-danger btn-xs" onclick="delpro(<?php echo $result['id'] ?>)">删除</button>
                      </th>
                      <th><button class="btn btn-info btn-xs">
                          <?php
                          switch ($result['pRank']) {
                            case 1:
                              # code...
                              echo ("申请立项");
                              break;
                            case 2:
                              # code...
                              echo ("立项成功");
                              break;
                            case 3:
                              # code...
                              echo ("立项失败");
                              break;
                            case 4:
                              # code..
                              echo ("申请结项");
                              break;
                            case 5:
                              # code...
                              echo ("结项成功");
                              break;
                            case 5:
                              # code...
                              echo ("结项失败");
                              break;
                            default:
                              # code...
                              echo ("优秀项目");
                              break;
                          }
                          ?>
                        </button></th>
                    </tr>
                  <?php

                }

                ?>
                </tbody>
              </table>
              <!-- </form> -->
              <?php
              if ($prepage <= 0) {
                $prepage = 1;
              }
              if ($nextpage > $tatolpage) {
                $nextpage = $page;
              }
              ?>
              <?php
              if ($prepage < 0) {
                $prepage = 0;
              }
              if ($nextpage > $tatolpage) {
                $nextpage = $page;
              }
              ?>
              <footer class="footer pull-right">
                <ul class="pagination">
                  <li><a href="project-list.php?page=0"><i class=" fa fa-fast-backward" style="color:rgb(19,137,95);font-size:20px;"></i></a></li>
                  <li><a href="project-list.php?page=<?php echo $prepage ?>"><i class="fa fa-backward " style="color:rgb(19,137,95);font-size:20px;  "></i></a></li>
                  <li class="gray">
                    <span style="font-size:15px; height: 45px;padding-top:13px;">第 <?php echo $page ?> 页</span>
                  </li>
                  <li><a href="project-list.php?page=<?php echo $nextpage ?>"><i class="  fa fa-forward" style="color:rgb(19,137,95);font-size:20px;"></i></a></li>
                  <li><a href="project-list.php?page=<?php echo $tatolpage ?>"><i class=" fa fa-fast-forward" style="color:rgb(19,137,95);font-size:20px; "></i></a></li>
                </ul>
              </footer>
              <div class="data-div">
                <!-- <input  value="下载" onclick="download()" class="btn btn-success btn-sm"> -->
                <input value="下载" type="submit" class="btn btn-success btn-sm">

              </div>

            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
</body>

</html>